<?php


namespace App\Job;


use Predis\Client;

class RedisJob extends Jobs
{

    protected $redis;

    protected $job;

    public function __construct(Client $redis, $job, $queue, $reserved)
    {
        $this->queue = $queue;
        $this->reserved = $reserved;
        $this->redis = $redis;
        $this->job = $job;
    }


    public function delete()
    {
        parent::delete();

        $this->redis->zrem($this->queue . ':reserved', $this->getReservedJob());
    }


    public function getRawBody()
    {
        return $this->job;
    }

    public function handle()
    {
        unserialize($this->payload()['job'])->handle();
        $this->delete();
    }
}